////////////////////////////////////////////////////////
// TrainingGrounds.cpp
////////////////////////////////////////////////////////

#include <d3d8.h>
#include "constants.h"
#include "MyEngine.h"
#include "TrainingGrounds.h"

extern CMyEngine g_Engine;

// Quest flags.
BOOL bSpokeToGrewell = FALSE;
BOOL bSpokeToWillam = FALSE;
BOOL bWillamQuestComplete = FALSE;
BOOL bHasWillamKey = FALSE;
BOOL bGotUniform = FALSE;

////////////////////////////////////////////////////////
// HandleTrainingGrounds()
////////////////////////////////////////////////////////
void HandleTrainingGrounds()
{

    switch (g_Engine.GetPlayer()->GetSector())
    {
    case HOUSE01FRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(HOUSE01FRONTDOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsHouse01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE01ROOM01);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownIntTileSurface()); 
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNFRONTDOOR:
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNFRONTDOOR + 1);
        g_Engine.SaveGame(FALSE);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM01);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownIntTileSurface());
        g_Engine.ResetAnimation();
        break;
    case HOUSE02FRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(HOUSE02FRONTDOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsHouse02Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE02ROOM01);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownIntTileSurface());
        g_Engine.ResetAnimation();
        break;
    case ARMORERFRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(ARMORERFRONTDOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsArmorer.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsARMORER);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownIntTileSurface());
        g_Engine.ResetAnimation();
        break;
    case POTIONSFRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(POTIONSFRONTDOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsPotions.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsPOTIONS);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownIntTileSurface());
        g_Engine.ResetAnimation();
        break;
    case GANJEKENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(902);
        g_Engine.OpenMapFiles("GanjekWilds.map", FALSE);
        g_Engine.SetCurrentMap(GANJEKWILDS);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetWildernessTileSurface());
        g_Engine.ResetAnimation();
		g_Engine.GetCDirectSoundObj()->StopMusic(g_Engine.GetCDirectSoundObj()->GetCurrentlyPlaying());
		g_Engine.GetCDirectSoundObj()->PlayMusic(Wilds);
        break;
    case DUNGEON02ENTRANCE:
        g_Engine.SaveGame(FALSE);
        if (bSpokeToWillam)
        {
            g_Engine.GetPlayer()->SetSector(DUNGEON02EXIT - MAPCOLUMNCOUNT);
            g_Engine.OpenMapFiles("TrainingGroundsDungeon02.map", FALSE);
            g_Engine.SetCurrentMap(TrainingGroundsDUNGEON02);
            g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
                (g_Engine.GetCDirect3DObj()->GetDungeonTileSurface());
            g_Engine.ResetAnimation();
        }
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsHouse01Room01()
////////////////////////////////////////////////////////
void HandleTrainingGroundsHouse01Room01()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case HOUSE01FRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(HOUSE01FRONTDOOR + 1);
        g_Engine.OpenMapFiles("TrainingGrounds.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGrounds);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownExtTileSurface());
        g_Engine.ResetAnimation();
        break;
    case HOUSE01ROOM01DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(HOUSE01ROOM01DOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsHouse01Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE01ROOM02);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsHouse01Room02()
////////////////////////////////////////////////////////
void HandleTrainingGroundsHouse01Room02()
{
    if (g_Engine.GetPlayer()->GetSector() == HOUSE01ROOM01DOOR)
    {
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(HOUSE01ROOM01DOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsHouse01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE01ROOM01);
        g_Engine.ResetAnimation();
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom01()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom01()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNFRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNFRONTDOOR - 1);
        g_Engine.OpenMapFiles("TrainingGrounds.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGrounds);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownExtTileSurface());
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNROOM02DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM02DOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM02);
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNROOM03DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM03DOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom03.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM03);
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNROOM04DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM04DOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom04.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM04);
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNROOM05DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM05DOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom05.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM05);
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNROOM06STAIRS:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM06STAIRS - 
            MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom06.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM06);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom02()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom02()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNROOM02DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM02DOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom03()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom03()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNROOM03DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM03DOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom04()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom04()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNROOM04DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM04DOOR + 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom05()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom05()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNROOM05DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM05DOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom06()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom06()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNROOM07DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM07DOOR - 
            MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom07.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM07);
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsINNROOM06STAIRS:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM05DOOR - 1);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsInnRoom07()
////////////////////////////////////////////////////////
void HandleTrainingGroundsInnRoom07()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case TrainingGroundsINNROOM07DOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(TrainingGroundsINNROOM07DOOR + 
            MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsInnRoom06.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsINNROOM06);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsHouse02Room01()
////////////////////////////////////////////////////////
void HandleTrainingGroundsHouse02Room01()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case HOUSE02FRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(HOUSE02FRONTDOOR - 1);
        g_Engine.OpenMapFiles("TrainingGrounds.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGrounds);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownExtTileSurface());
        g_Engine.ResetAnimation();
        break;
    case HOUSE02ROOM02ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.OpenMapFiles("TrainingGroundsHouse02Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE02ROOM02);
        g_Engine.ResetAnimation();
        break;
        }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsArmorer()
////////////////////////////////////////////////////////
void HandleTrainingGroundsArmorer()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case ARMORERFRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(ARMORERFRONTDOOR - 1);
        g_Engine.OpenMapFiles("TrainingGrounds.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGrounds);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownExtTileSurface());
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsPotions()
////////////////////////////////////////////////////////
void HandleTrainingGroundsPotions()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case POTIONSFRONTDOOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->SetSector(POTIONSFRONTDOOR - 1);
        g_Engine.OpenMapFiles("TrainingGrounds.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGrounds);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownExtTileSurface());
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsHouse02Room02()
////////////////////////////////////////////////////////
void HandleTrainingGroundsHouse02Room02()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case HOUSE02ROOM02ENTRANCE - 2:
        g_Engine.SaveGame(FALSE);
        g_Engine.OpenMapFiles("TrainingGroundsHouse02Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE02ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM01ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetDungeonTileSurface());
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room01()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room01()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM01ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ENTRANCE - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsHouse02Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsHOUSE02ROOM02);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownIntTileSurface());
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM02ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM02);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM07ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM07ENTRANCE - 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room07.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM07);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM09ENTRANCE1:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM09ENTRANCE1 + 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room09.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM09);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM09ENTRANCE2:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM09ENTRANCE2 + 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room09.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM09);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM09ENTRANCE3:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM09ENTRANCE3 - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room09.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM09);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM10ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM10ENTRANCE - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room10.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM10);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM11ENTRANCE1:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM11ENTRANCE1 - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room11.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM11);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM11ENTRANCE2:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM11ENTRANCE2 - 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room11.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM11);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM11ENTRANCE3:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM11ENTRANCE3 - 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room11.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM11);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room02()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room02()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM02ENTRANCE - 2:
        g_Engine.SaveGame(FALSE);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM03ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM03ENTRANCE - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room03.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM03);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM04ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM04ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room04.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM04);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM05ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM05ENTRANCE - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room05.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM05);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM06ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM06ENTRANCE - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room06.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM06);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room03()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room03()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM03ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM03ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM02);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room04()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room04()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM04ENTRANCE - MAPCOLUMNCOUNT*2:
        g_Engine.SaveGame(FALSE);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM02);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room05()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room05()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM05ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM05ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM02);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room06()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room06()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM06ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM06ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM02);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room07()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room07()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM07ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM07ENTRANCE + 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room08()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room08()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM08ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM08ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room10.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM10);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room09()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room09()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM09ENTRANCE1:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM09ENTRANCE1 -  1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM09ENTRANCE2:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM09ENTRANCE2 -  1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM09ENTRANCE3:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM09ENTRANCE3 + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case TrainingGroundsDUNGEON01WARPSECTOR:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(TrainingGroundsDUNGEON01WARPTARGET);
        break;
    case TrainingGroundsDUNGEON01ACCESSGRATE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(691);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Level02.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01LEVEL02);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room10()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room10()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM10ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM10ENTRANCE + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM08ENTRANCE:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM08ENTRANCE - MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room08.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM08);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Room11()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Room11()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM11ENTRANCE1:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM11ENTRANCE1 + MAPCOLUMNCOUNT);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM11ENTRANCE2:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM11ENTRANCE2 + 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    case DUNGEON01ROOM11ENTRANCE3:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON01ROOM11ENTRANCE3 + 1);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room01.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM01);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon01Level02()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon01Level02()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON01ROOM09ENTRANCE02:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(TrainingGroundsDUNGEON01WARPTARGET);
        g_Engine.OpenMapFiles("TrainingGroundsDungeon01Room09.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGroundsDUNGEON01ROOM09);
        g_Engine.ResetAnimation();
        break;
    }
}

////////////////////////////////////////////////////////
// HandleTrainingGroundsDungeon02()
////////////////////////////////////////////////////////
void HandleTrainingGroundsDungeon02()
{
    switch (g_Engine.GetPlayer()->GetSector())
    {
    case DUNGEON02EXIT:
        g_Engine.SaveGame(FALSE);
        g_Engine.GetPlayer()->
            SetSector(DUNGEON02ENTRANCE - 1);
        g_Engine.GetCDirect3DObj()->SetCurrentTileSurface
            (g_Engine.GetCDirect3DObj()->GetTownExtTileSurface());
        g_Engine.OpenMapFiles("TrainingGrounds.map", FALSE);
        g_Engine.SetCurrentMap(TrainingGrounds);
        g_Engine.ResetAnimation();
        break;
    }
}

//////////////////////////////////////////////////////
// HandleFennelGridrock()
//////////////////////////////////////////////////////
void HandleFennelGridrock()
{
    g_Engine.TurnOnPlaque(
"I'm Fennel Gridrock, a guard\n\
here at First Town. I hope you\n\
enjoy your stay.");
}

//////////////////////////////////////////////////////
// HandleUrisYamdolf()
//////////////////////////////////////////////////////
void HandleUrisYamdolf()
{
    if (bSpokeToGrewell)
        g_Engine.TurnOnPlaque(
"I'm Uris Yamdolf, a guard\n\
here at First Town. It's nice to\n\
have you here helping\n\
the citizens.");
    else
        g_Engine.TurnOnPlaque(
"I'm Uris Yamdolf, a guard\n\
here at First Town. You're Jasper,\n\
right? You're supposed to talk\n\
with Grewell Pessle as soon\n\
as you can.");
}

//////////////////////////////////////////////////////
// HandleGrewellPessle()
//////////////////////////////////////////////////////
void HandleGrewellPessle()
{
    if (!bSpokeToGrewell)
    {
        g_Engine.TurnOnPlaque(
"I'm Grewell Pessle, one of the\n\
town Councilmen. Willam Groves'\n\
son lost his puppy. Find the puppy,\n\
and I'll give you something useful\n\
Speak to Willam for more\n\
information about the puppy.");
        bSpokeToGrewell = TRUE;
    }
    else if (bSpokeToGrewell && !bWillamQuestComplete)
        g_Engine.TurnOnPlaque( 
"You're supposed to be finding\n\
that puppy, remember? Talk to\n\
Willam Groves.");
    else if (bWillamQuestComplete && !bHasWillamKey)
    {
        g_Engine.TurnOnPlaque(
"Great job finding the puppy!\n\
Here's the key you\n\
need to get into the\n\
abandoned house.");
        bHasWillamKey = TRUE;
    }
    else if (bHasWillamKey)
    {
        g_Engine.TurnOnPlaque(
"Thanks for your help\n\
finding the puppy.");
        bHasWillamKey = TRUE;
    }
}

//////////////////////////////////////////////////////
// HandleWillamGroves()
//////////////////////////////////////////////////////
void HandleWillamGroves()
{
    if (bSpokeToWillam && !bWillamQuestComplete)
        g_Engine.TurnOnPlaque(
"My son is very unhappy.\n\
Please find his puppy.");
    else if (bSpokeToGrewell && !bSpokeToWillam)
    {
        g_Engine.TurnOnPlaque(
"Hi, Jasper. Grewell told me\n\
that he spoke to you. I'm Willam\n\
Groves. My son said he last saw\n\
his dog somewhere in the\n\
northwest of the town.");
        bSpokeToWillam = TRUE;
    }
    else if (bWillamQuestComplete)
        g_Engine.TurnOnPlaque(
"Hi again, Jasper! My son is\n\
thrilled to have his puppy back.\n\
Did you see Grewell Passle\n\
about your reward?");
    else
        g_Engine.TurnOnPlaque(
"Hello, stranger.\n\
I'm Willam Groves.");
}

//////////////////////////////////////////////////////
// FinishWillamQuest()
//////////////////////////////////////////////////////
void FinishWillamQuest()
{
    if (!bWillamQuestComplete)
    {
        g_Engine.TurnOnPlaque("You find a small puppy,\n\
which you tuck safely\nunder your arm.");
        bWillamQuestComplete = TRUE;
    }
    else
        g_Engine.TurnOnPlaque("You find nothing.");
}

//////////////////////////////////////////////////////
// OpenAbandonedHouse()
//////////////////////////////////////////////////////
BOOL OpenAbandonedHouse()
{
    if (bHasWillamKey)
    {
        g_Engine.TurnOnPlaque(
"You use the key you got\n\
from Grewell Pessle to\n\
open the door.");
        return TRUE;
    }
    g_Engine.TurnOnPlaque("You need a special key.");
    return FALSE;
}

//////////////////////////////////////////////////////
// HandleArstinBlack()
//////////////////////////////////////////////////////
void HandleArstinBlack()
{
    g_Engine.TurnOnPlaque(
"I'm Arstin Black, the\n\
proprietor of this shop.\n\
Would you like to buy a\n\
potion for 8 gold pieces?\n\
(Y/N)");
    g_Engine.SetPurchasePrice(8);
}

//////////////////////////////////////////////////////
// HandlePaltumGanges()
//////////////////////////////////////////////////////
void HandlePaltumGanges()
{
    if (g_Engine.GetPlayer()->GetArmor() == 0) 
    {
        g_Engine.TurnOnPlaque(
"I'm Paltum Ganges, the\n\
proprietor of this shop.\n\
Would you like to buy\n\
level 1 armor for 100 gold pieces?\n\
(Y/N)");
    g_Engine.SetPurchasePrice(100);
    g_Engine.SetNewArmorLevel(1);
    }
    else if (g_Engine.GetPlayer()->GetWeapon() == 0) 
    {
        g_Engine.TurnOnPlaque(
"I'm Paltum Ganges, the\n\
proprietor of this shop.\n\
Would you like to buy a\n\
level 1 sword for 100 gold pieces?\n\
(Y/N)");
    g_Engine.SetPurchasePrice(100);
    g_Engine.SetNewWeaponLevel(1);
    }
    else 
    {
        g_Engine.TurnOnPlaque(
"I'm Paltum Ganges, the\n\
proprietor of this shop.\n\
I'm afriad that I have no\n\
armor or weapons that\n\
can help you now.");
    g_Engine.SetPurchasePrice(100);
    g_Engine.SetNewWeaponLevel(1);
    }
}

//////////////////////////////////////////////////////
// HandleBilliamAberton()
//////////////////////////////////////////////////////
void HandleBilliamAberton()
{
    g_Engine.TurnOnPlaque(
"I'm Billiam Aberton, the\n\
proprietor of this inn.\n\
Would you like to stay\n\
the night for 6 gold pieces?\n\
(Y/N)");
    g_Engine.SetPurchasePrice(6);
}

//////////////////////////////////////////////////////
// HandleJalbitFrandy()
//////////////////////////////////////////////////////
void HandleJalbitFrandy()
{
    if (!bGotUniform)
        g_Engine.TurnOnPlaque(
"You know that abandoned house\n\
on the east side of town?\n\
I've heard that people who\n\
go in there, never come\n\
out again. What's up with that?");
    else
        g_Engine.TurnOnPlaque(
"Hi, Jasper. That uniform you're\n\
wearing looks just like the\n\
ones they wear in Second Town.");
}

//////////////////////////////////////////////////////
// HandleKyleManderbump()
//////////////////////////////////////////////////////
void HandleKyleManderbump()
{
    if (!bGotUniform)
        g_Engine.TurnOnPlaque(
"You have to watch out for\n\
the guards in Second Town.\n\
They arrest all strangers as spies.");
    else
        g_Engine.TurnOnPlaque(
"That green uniform you're\n\
wearing makes you look just\n\
like a citizen of Second Town.\n\
It's a good thing that people\n\
here in First Town don't worry\n\
about spies!");
}

//////////////////////////////////////////////////////
// HandleHoolbertWamstam()
//////////////////////////////////////////////////////
void HandleHoolbertWamstam()
{
        g_Engine.TurnOnPlaque(
"Hi. I'm Hoolbert Wamstam.\n\
Did you know that you can buy\n\
a sword and some armor at\n\
Paltum Ganges's armor shop? His stuff\n\
is expensive but well worth it\n\
if you plan on leaving the town or\n\
exploring dungeons.");
}

//////////////////////////////////////////////////////
// HandleOngellAnderwel()
//////////////////////////////////////////////////////
void HandleOngellAnderwel()
{
        g_Engine.TurnOnPlaque(
"Hi. I'm Ongell Anderwel.\n\
Battling monsters with your\n\
bare hands is tough business.\n\
Once you have enough money, you\n\
should invest in a weapon and\n\
some armor. And don't forget\n\
a potion or three!");
}

//////////////////////////////////////////////////////
// HandleKelbertPallaster()
//////////////////////////////////////////////////////
void HandleKelbertPallaster()
{
        g_Engine.TurnOnPlaque(
"Hi. Kelbert Pallaster at your\n\
service. Don't forget to visit the\n\
potion shop before you try to\n\
battle monsters. A potion or two\n\
can save your life when your\n\
wounds get bad.");
}

//////////////////////////////////////////////////////
// HandleBenttamGaggleThorp()
//////////////////////////////////////////////////////
void HandleBenttamGagglethorp()
{
    if (!bSpokeToGrewell)
        g_Engine.TurnOnPlaque(
"I heard somewhere that Grewell\n\
Pessle is looking for you.\n\
Something about a lost puppy, I\n\
think. Grewell usually hangs\n\
around the inn.");
    else
        g_Engine.TurnOnPlaque(
"Hi, Jasper. Did you know\n\
that dungeons sometimes have\n\
invisible teleporters that\n\
can take you places that aren't\n\
accessible any other way? You\n\
need to search hard to find\n\
a teleporter.");
}

//////////////////////////////////////////////////////
// HandleMartalEndwip()
//////////////////////////////////////////////////////
void HandleMartalEndwip()
{
        g_Engine.TurnOnPlaque(
"Sometimes if you step in\n\
just the right place, you'll\n\
find a teleporter. Also, I've\n\
heard that some sewer grates\n\
lead to secret rooms. This is\n\
especially true in dungeons.");
}

//////////////////////////////////////////////////////
// HandleKellersWilopp()
//////////////////////////////////////////////////////
void HandleKellersWilopp()
{
    static int iTalkCount = 0;
    if (iTalkCount == 0)
        g_Engine.TurnOnPlaque(
"What are you doing in\n\
my room? Go away!");
    else if (iTalkCount == 1)
        g_Engine.TurnOnPlaque(
"You again? I thought I\n\
told you to go away!");
    else
        g_Engine.TurnOnPlaque(
"I'm going to call the guards\n\
if you don't leave me alone!");
    ++iTalkCount;
    if (iTalkCount > 2) iTalkCount = 0;
}

//////////////////////////////////////////////////////
// HandleJeriJackapple()
//////////////////////////////////////////////////////
void HandleJeriJackapple()
{
    if (!bHasWillamKey)
        g_Engine.TurnOnPlaque(
"There's an abandoned house\n\
right across the street from\n\
here. I've heard lots of nasty\n\
stories about that place.");
    else
        g_Engine.TurnOnPlaque(
"Now that you have the key,\n\
I guess you won't be able to\n\
resist going into that abandoned\n\
house. Better bring some\n\
potions with you.");
}

//////////////////////////////////////////////////////
// FinishUniformQuest()
//////////////////////////////////////////////////////
void FinishUniformQuest()
{
    if (!bGotUniform)
    {
        g_Engine.TurnOnPlaque(
"You find a uniform just like\n\
the ones they wear in Second Town,\n\
and you put it on.");
        bGotUniform = TRUE;
    }
    else
        g_Engine.TurnOnPlaque("You find nothing.");
}
